package cn.ekuma.epos.analysis.front.model;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.openbravo.bean.erp.viewbean.PassengerFlowAnalysisInfo;
import com.openbravo.format.Formats;

import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.util.RoundUtils;

public class PassengerFlowAnalysisTableModel extends AbstractTableModel{
    
    List<PassengerFlowAnalysisInfo> rows;
    
    public PassengerFlowAnalysisTableModel() {
        rows=new ArrayList();
    }

    public void resert( List<PassengerFlowAnalysisInfo> rows){
        this.rows=rows;
        this.fireTableStructureChanged();
    }

    public int getRowCount() {
        return rows.size();
    }

    @Override
    public String getColumnName(int column) {
        return COLUMNS[column];
    }

    public int getColumnCount() {
        return COLUMNS.length;
    }

    public PassengerFlowAnalysisInfo get(int index){
        return rows.get(index);
    }

    public static String[] COLUMNS=new String[]{
           AppLocal.getIntString("label.hostName"),
           AppLocal.getIntString("label.warehouse"),
           AppLocal.getIntString("label.ordertypedialog.bearing"),
           AppLocal.getIntString("label.units"),
           AppLocal.getIntString("label.pricesellCount"),
           AppLocal.getIntString("label.pricebuyCount"),
           AppLocal.getIntString("label.profits")
    };
    

    public Object getValueAt(int rowIndex, int columnIndex) {
    	PassengerFlowAnalysisInfo obj=rows.get(rowIndex);
    	switch(columnIndex){
    	case 0:
    		return obj.getHostName();
    	case 1:
    		return obj.getLocation();
    	case 2:
    		return obj.getType();
    	case 3:
    		return obj.getUnit();
    	case 4:
    		return RoundUtils.round(obj.getTotalPrice());
    	case 5:
    		return RoundUtils.round(obj.getConsultCost());
    	case 6:
    		return RoundUtils.round(obj.getTotalPrice()-obj.getConsultCost());
    	}
        return null;
    }

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		if(columnIndex==4||columnIndex==5||columnIndex==6){
			return Double.class;
		}
		return super.getColumnClass(columnIndex);
	}
    
    
}
